<template>
  <div class="app-container">
    <!-- 工具栏 -->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.blurry"
          placeholder="采购单位"
          size="small"
          class="filter-item"
          style="width: 140px"
        />
        <rrOperation :crud="crud" @resetQuery="onResetQuery"/>
      </div>
      <crudOperation :permissions="permission"></crudOperation>
    </div>
    <!-- 表格渲染 -->
    <el-table
      ref="table"
      v-loading="crud.loading" 
      :data="crud.data"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column v-if="columns.visible('name')" label="采购单位" prop="name"></el-table-column>
      <el-table-column v-if="columns.visible('coefficient')" label="换算系数" prop="coefficient"></el-table-column>
      <el-table-column v-if="columns.visible('createTime')" label="创建时间" prop="createTime">
        <template slot-scope="{row}" >{{ parseTime(row.createTime) }}</template>
      </el-table-column>
      <el-table-column v-if="columns.visible('updateTime')" label="修改时间" prop="updateTime">
        <template slot-scope="{row}" >{{ parseTime(row.updateTime) }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <udOperation
            :data="scope.row"
            :permissions="permission"
          />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination />
    <!-- 新增、编辑 -->
    <factorForm></factorForm>
  </div>
</template>

<script>
import CRUD, { presenter, header } from "@crud/crud";

import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import pagination from "@crud/Pagination";
import factorForm from "./module/form";
import crudFactor from "@/api/system/factor";
import udOperation from '@crud/UD.operation';
import { parseTime } from '@/utils/index';

let defaultCrud = CRUD({
  title: "系数管理",
  url: "api/conversionFactor",
  crudMethod: { ...crudFactor },
  query: {blurry: null}
});

export default {
  name: "supplier",
  components: { crudOperation, rrOperation, pagination, factorForm, udOperation },
  mixins: [presenter(defaultCrud), header()],
  data() {
    return {
      permission: [
        {
          type: "add",
          position: 1,
          permission: ["admin", "conversionFactor:add"]
        },
        {
          type: "edit",
          permission: ["admin", "conversionFactor:edit"]
        },
        {
          type: "delete",
          permission: ["admin", "conversionFactor:del"]
        }
      ],
      showDialog: false
    }
  },
  created() {
    this.crud.toQuery();
  },
  methods: {
    parseTime,
    onResetQuery() {
      this.query.pharmacyId = this.pharmacyId;
    }
  }
}
</script>